#ifndef __DEBUG_H__
#define __DEBUG_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <string.h>

#define	DBG_PRINTF_FUNC		(1)
#define	DBG_PRINTF_SWITCH	(1)
#define	COLOR_DEBUG_FUNC	(1)

// color debug
#ifdef COLOR_DEBUG_FUNC
#define NONE		"\e[m"
#define RED			"\e[0;31m"
#define GREEN		"\e[0;32m"
#define YELLOW		"\e[0;33m"
#define BLUE		"\e[0;34m"
#else
#define NONE
#define RED
#define GREEN
#define YELLOW
#define BLUE
#endif

#define NEWLINE		"\n"
#define	debug_msg	printf

#ifdef DBG_PRINTF_FUNC
#define	DBG_PRINTF(fmt, args...)	\
		do{\
		debug_msg("<"BLUE"%s"NONE">("RED"%d"NONE")["GREEN"%s"NONE"]:", \
		strrchr(__FILE__, '/')?strrchr(__FILE__, '/')+1:__FILE__, __LINE__, __FUNCTION__);\
		debug_msg(fmt, ##args);\
		}while(0)

#define	DBG_PRINTF_K(key,fmt, args...)	\
		if(key){\
		debug_msg("<<FILE:"BLUE"%s"NONE" LINE:"RED"%d"NONE" FUNC:"GREEN"%s"NONE">>", \
		strrchr(__FILE__, '/')?strrchr(__FILE__, '/')+1:__FILE__, __LINE__, __FUNCTION__);\
		debug_msg(fmt, ##args);\
		}
/*
#define	DBG_WRN(fmt, args...)   \
    do{\
        debug_msg(YELLOW);\
        debug_msg(fmt, ##args);\
        debug_msg(NONE""NEWLINE);\
    }while(0)

#define DBG_ERR(fmt, args...)   \
    do{\
        debug_msg(RED);\
        debug_msg(fmt, ##args);\
        debug_msg(NONE""NEWLINE);\
    }while(0)
*/

//#define DBG_WRN(fmtstr, args...) fprintf(PRINT_OUTFILE, "\033[33m%s(): \033[0m" fmtstr,__func__, ##args)
//#define DBG_ERR(fmtstr, args...) fprintf(PRINT_OUTFILE, "\033[31m%s(): \033[0m" fmtstr,__func__, ##args)
#define DBG_WRN(fmtstr, args...) debug_msg("\033[33m%s(): \033[0m" fmtstr,__func__, ##args)
#define DBG_ERR(fmtstr, args...) debug_msg("\033[31m%s(): \033[0m" fmtstr,__func__, ##args)

#else
#define	DBG_PRINTF(fmt, args...)
#define	DBG_PRINTF_K(key,fmt, args...)
#define	DBG_WRN(fmt, args...)
#define DBG_ERR(fmt, args...)
#endif /* DBG_PRINTF_FUNC */

#ifdef __cplusplus
}
#endif

#endif /* __DEBUG_H__ */
